var hue=0,saturate=50,luminosity=50,clicked=false;
var HSL_prefixe="",num_w = 0;

function add_pickcolor_HSL(file,noeud,num)
{
	prefixe_tool = noeud
	num_w = num
	hue=0
	saturate=50
	luminosity=50
	rect_color = "rgb(191,63,63)"
	clicked = false
	getSVGObject(file, tool_pickcolor_HSL)
};

function tool_pickcolor_HSL( doc_frag ) 
{
	var node = svgdoc.getElementById(prefixe_tool);
	node.appendChild (doc_frag)
	svgdoc.getElementById("pickcolor_header").firstChild.data = popup_message[8] + " "
	svgdoc.getElementById("pickcolor_comment").firstChild.data = popup_message[9] + " "
	svgdoc.getElementById("pickcolor_ok").firstChild.data = popup_message[10]
	svgdoc.getElementById("pickcolor_cancel").firstChild.data = popup_message[11]
}

function close_colorHSL(choice)
{
	remove_tool("pick_color")
	eval("use_" + prefixe_tool + "_pickcolor_HSL(choice,rect_color,num_w)")
}

function move_colorHSL(evt,num)
{if (clicked)
	{
		if (ASV == "6")
		{
			var matrix = svgdoc.getElementById("test").getScreenCTM().inverse()
			xm = parseInt(evt.clientX * matrix.a + evt.clientY * matrix.c + matrix.e)
			ym = parseInt(evt.clientX * matrix.b + evt.clientY * matrix.d + matrix.f)
		}
		else
		{
			var matrix = svgdoc.getElementById("pick_color").getCTM().inverse()
			var xm1 = parseInt(pan_x * (1 - 1 / zoom) + coordo_x(evt.clientX) / zoom)
			var ym1 = parseInt(pan_y * (1 - 1 / zoom) + coordo_y(evt.clientY) / zoom)
			xm = xm1 * matrix.a + ym1 * matrix.c + matrix.e
			ym = xm1 * matrix.b + ym1 * matrix.d + matrix.f - 15
		}
	if (num == 1)
		{
		if (xm < 50) xm = 50
		if (xm > 410) xm = 410
		if (ym < 20) ym = 20
		if (ym > 220) ym = 220
		hue = xm - 50
		saturate = (220 - ym)/2
		svgdoc.getElementById("cursor1").setAttributeNS(null,"transform","translate("+(xm - 50) + "," + (ym - 120) +")")
		svgdoc.getElementById("h").firstChild.data = parseInt(hue).toString()
		svgdoc.getElementById("b").firstChild.data = parseInt(saturate).toString()
		}
	if (num == 2)
		{
		if (ym < 20) ym = 20
		if (ym > 220) ym = 220
		luminosity = (220 - ym)/2
		svgdoc.getElementById("cursor2").setAttributeNS(null,"transform","translate(0,"+ (ym - 120) +")")
		svgdoc.getElementById("l").firstChild.data = parseInt(luminosity).toString()		
		}
	rect_color = convertHSLtoRGB(evt,luminosity/100,saturate/100,hue/360)
	svgdoc.getElementById("test").setAttributeNS(null,"fill",rect_color)
	svgdoc.getElementById("dec").firstChild.data = rect_color		
	}
}

function convertHSLtoRGB(evt,l,s,h)
{
if (s == 0)
	{ 
	red = l
	green = l
	blue = l
	}
	else
	{
	if (l < 0.5) temp2 = l * (1.0 + s) 
	else 
	temp2 = l + s - l * s
	temp1 = 2 * l - temp2
	rtemp3 = h + 1 / 3
	if (rtemp3 < 0) rtemp3 = rtemp3 + 1.0
	if (rtemp3 > 1) rtemp3 = rtemp3 - 1.0
	gtemp3 = h
	btemp3 = h - 1 / 3
	if (btemp3 < 0) btemp3 = btemp3 + 1.0
	if (btemp3 > 1) btemp3 = btemp3 - 1.0
	if (rtemp3 < 1/6) red = temp1 + (temp2 - temp1) * 6 * rtemp3
	else
		{
		if (rtemp3 < 0.5) red = temp2
		else
			{
			if (rtemp3 < 2/3) red = temp1 + (temp2 - temp1) * (2 / 3 - rtemp3) * 6
			else
			red = temp1;
			}
		}
	if (gtemp3 < 1/6) green = temp1 + (temp2 - temp1) * 6 * gtemp3
	else
		{
		if (gtemp3 < 0.5) green = temp2
		else
			{
			if (gtemp3 < 2/3) green = temp1 + (temp2 - temp1) * (2 / 3 - gtemp3) * 6
			else
			green = temp1;
			}
		}
	if (btemp3 < 1/6) blue = temp1 + (temp2 - temp1) * 6 * btemp3
	else
		{
		if (btemp3 < 0.5) blue = temp2
		else
			{
			if (btemp3 < 2/3) blue = temp1 + (temp2 - temp1) * (2 / 3 - btemp3) * 6
			else
			blue = temp1;
			}
		}

	}  
red = parseInt(red * 255)
green = parseInt(green * 255)
blue = parseInt(blue * 255)
var rgb_color = "rgb(" + red + "," + green + "," + blue + ")"
return rgb_color
}
